#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Apr  8 19:15:50 2021

@author: cl
"""
# numpy 函数测试
# hstack, vstack, stack

import numpy as np

a = np.zeros((5, ))
b = np.ones((8, ))
c = np.hstack((a, b))

a1 = np.zeros((3, 5))
b1 = np.ones((3, 8))
d1 = np.zeros((3, 6))
u1 = [a1, b1, d1]
c1 = np.hstack((a1, b1, d1)) # 元组形式
c11 = np.hstack(u1) # list形式

a2 = np.zeros((5, 3))
b2 = np.ones((8, 3))
d2 = np.zeros((6, 3))
u2 = [a2, b2, d2]
c2 = np.vstack((a2, b2, d2))
c22 = np.vstack(u2)

a3 = np.zeros((5, 6, 2))
b3 = np.ones((5, 6, 4))
d3 = np.zeros((5, 6, 3))
u3 = [a3, b3, d3]
c3 = np.dstack((a3, b3, d3))
c33 = np.dstack(u3)

arrays = [np.random.randn(3, 4) for _ in range(10)]
np.stack(arrays, axis=0).shape
# out is (10, 3, 4)
np.stack(arrays, axis=1).shape
# out is (3, 4, 10)

a4 = np.zeros((3, 4))
b4 = np.ones((3, 4))
c4 = np.concatenate((a4, b4), axis=0)
c44 = np.concatenate((a4, b4), axis=1)

a4 = np.zeros((2, 3, 4))
b4 = np.ones((5, 3, 4))
c4 = np.concatenate((a4, b4), axis=0)

a4 = np.zeros((3, 4, 2))
b4 = np.ones((3, 4, 5))
c4 = np.concatenate((a4, b4), axis=2)

v1 = np.ones((1, 5))
v2 = np.ones((5, 6))
v3 = np.dot(v1, v2)
#
v1 = np.ones((5, ))
v2 = np.ones((5, 6))
v3 = np.dot(v1, v2)

# squeeze测试，去掉维度是1的那一维
e1 = np.zeros((1,3,1))
e2 = np.squeeze(e1, axis=0)
e3 = np.squeeze(e1, axis=2)
e4 = np.squeeze(e1, axis=-1)
f1 = np.zeros((2,3,5))
f2 = np.expand_dims(f1, axis=0) # unsqueeze用expand_dims代替
f3 = np.expand_dims(f1, axis=2)

print(f2.shape)
print(f3.shape)
